<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<title>添加设备信息 - 设备信息管理</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-equipment-add">
	<div class="row cl">
		
    	<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>设备编号：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" placeholder="请输入设备编号" name="no">
		</div>
	</div>
	<div class="row cl">
		
    	<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>设备名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" placeholder="请输入设备名称" name="name">
		</div>
	</div>
	<div class="row cl">
		
    	<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>设备数量：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" placeholder="请输入设备数量" name="num">
		</div>
	</div>
	<div class="row cl">
		
    	<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>设备描述：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" placeholder="请输入设备描述" name="desp">
		</div>
	</div>
	<div class="row cl">
		
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>采购时间：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" style="width:200px;" placeholder="请输入采购时间" name="perchaseTime">
		</div>
	</div>
	
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>

<jsp:include page="_footer.jsp" flush="true"></jsp:include>
<script type="text/javascript" src="${path }/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
var equipmentId;
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-equipment-add").validate({
		rules:{
        	no:{
				required:true
			},
        	name:{
				required:true
			},
        	num:{
				required:true
			},
        	desp:{
				required:true
			},
        	perchaseTime:{
				required:true
			}
		},
		onkeyup:false,
		success:"valid",
		submitHandler:function(form){
			addOrUpdateEquipment();
		}
	});
});

function addOrUpdateEquipment(){
	var url = "${path}/equipment/add.do";
	var type = '添加';
	var formData = $('#form-equipment-add').serialize();
	if (equipmentId) {
		url = "${path}/equipment/update.do";
		type = '修改';
		formData += '&id='+equipmentId;
	}
	jajax({
		url: url,
		data: formData, 
		type: "POST",
		success: function(data, textStatus){
			layer.msg(type+'成功!',{icon:1,time:1000});
			setTimeout(function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.refresh(index);
			}, 1500);
		}
	});	
	
}

function fillData(id){
	equipmentId = id;
	jajax({
		url: "${path}/equipment/detail.do",
		data: 'id='+id, 
		type: "POST",
		success: function(data, textStatus){
			var obj = data.data;
			fillFormByName('form-equipment-add', obj, {perchaseTime:'datetime'});
		}
	});
}
</script> 
</body>
</html>
